//
//  SEExamineReserveEyeTypeCell.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/8.
//

import UIKit

protocol SEExamineReserveEyeTypeCellDelegate: NSObjectProtocol {
    func examineReserveEyeTypeCell(type: SEExamineReserveEyeType)
}

class SEExamineReserveEyeTypeCell: UITableViewCell {

    static let className = "SEExamineReserveEyeTypeCell"
    static let reuseId = className

    weak var delegate: SEExamineReserveEyeTypeCellDelegate?

    @IBOutlet weak var bothBtn: UIButton!
    @IBOutlet weak var leftBtn: UIButton!
    @IBOutlet weak var rightBtn: UIButton!

    @IBAction func bothBtnAction(_ sender: UIButton) {
        delegate?.examineReserveEyeTypeCell(type: .both)
    }

    @IBAction func leftBtnAction(_ sender: UIButton) {
        delegate?.examineReserveEyeTypeCell(type: .left)
    }

    @IBAction func rightBtnAction(_ sender: UIButton) {
        delegate?.examineReserveEyeTypeCell(type: .right)
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    func updateCell(vm: SEExamineReserveViewModel) {
        bothBtn.isSelected = vm.checkEyeType == .both
        leftBtn.isSelected = vm.checkEyeType == .left
        rightBtn.isSelected = vm.checkEyeType == .right
        setBtnBorder(btn: bothBtn)
        setBtnBorder(btn: leftBtn)
        setBtnBorder(btn: rightBtn)
    }

    private func setBtnBorder(btn: UIButton) {
        btn.layer.cornerRadius = 2
        btn.layer.borderWidth = 1
        btn.layer.masksToBounds = true
        if btn.isSelected {
            btn.layer.borderColor = UIColor.init(hex: "4AD4AC").cgColor
        } else {
            btn.layer.borderColor = UIColor.init(hex: "C8C8C8").cgColor
        }
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
